package jltx.fragmentpageframework.simple.fragment.shop;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import jltx.fragmentpageframework.R;
import jltx.fragmentpageframework.simple.fragment.base.BaseMainFragment;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2017/05/21.
 */

public class ShopFragment extends BaseMainFragment {

    private MenuListFragment menuListFragment;
    private ContentFragment contentFragment;
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_simple_shop,container,false);
        setToolbarTitle(R.string.menu_nav_simple_shop);
        initView(savedInstanceState);
        return rootView;
    }

    private void initView(Bundle savedInstanceState) {

        if (savedInstanceState == null) {
            ArrayList<String> listMenus = new ArrayList<>();
            listMenus.add("推荐分类");
            listMenus.add("京东超市");
            listMenus.add("全球购");
            listMenus.add("男装");
            listMenus.add("女装");
            listMenus.add("男鞋");
            listMenus.add("女鞋");
            listMenus.add("内衣配饰");
            listMenus.add("箱包手袋");
            listMenus.add("美妆个护");
            listMenus.add("钟表珠宝");
            listMenus.add("手机数码");
            listMenus.add("电脑办公");
            listMenus.add("家用电器");
            listMenus.add("食品生鲜");
            listMenus.add("酒水饮料");
            listMenus.add("母婴童装");
            listMenus.add("玩具乐器");
            listMenus.add("医药保健");
            listMenus.add("运动户外");
            listMenus.add("汽车用品");
            listMenus.add("家具厨具");
            listMenus.add("家具家装");

            menuListFragment = MenuListFragment.newInstance(listMenus);
            loadRootFragment(R.id.frg_container_menu_simple_shop, menuListFragment);
            contentFragment = ContentFragment.newInstance(listMenus.get(0));
            replaceLoadRootFragment(R.id.frg_container_content_simple_shop,contentFragment,false);
        }else {
            menuListFragment = findChildFragment(MenuListFragment.class);
            contentFragment = findChildFragment(ContentFragment.class);
        }
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
    }

    public void switchContentfragment(ContentFragment contentFragment){
        if(contentFragment != null){
            this.contentFragment = contentFragment;
            getFragmentImpl().replaceTransaction(getChildFragmentManager(),R.id.frg_container_content_simple_shop,contentFragment,false);
        }
    }
}
